/* ************************************************************************

   Copyright:
     2008 openWorks

   License:
     LGPL: http://www.gnu.org/licenses/lgpl.html
     See the LICENSE file in the project's top-level directory for details.

   Authors:
     * Juan Matias Granda

************************************************************************ */

/* ***
#asset(ow/icons/16/*)
#asset(ow/icons/64/*)
*/

/**
* TODO
* 
* *Ejemplo:*
*
* <pre class='javascript'>
* TODO
*  </pre>
*/

qx.Class.define("qx.ui.form.ow.Msg",
{
	extend : qx.ui.window.Window,

/*
*****************************************************************************
     EVENTS
*****************************************************************************
*/
	statics :
	{
		_Window : function (typeTitle, iconTitle, iconWindow, msg)
		{
			var win = new qx.ui.window.Window("Titulo");

			win.setCaption(typeTitle);
			win.setLayout(new qx.ui.layout.VBox(10,0));
			win.setShowStatusbar(false);	
			win.setShowClose(false);
			win.setShowMaximize(false);
			win.setAllowMaximize(false);
			win.setShowMinimize(false);
			win.setMarginLeft(0);
			win.setMarginRight(0);
			win.setWidth(350);
			win.setHeight(140);
			win.setModal(true);
			win.setMovable(true);
			win.setResizable(false);
			win.moveTo("33%","35%");
			win.setIcon(iconTitle);


			var imgWindow = new qx.ui.basic.Image(iconWindow);
			var txtMsg = new qx.ui.basic.Label("<b>"+msg+"</b>");
			txtMsg.setRich(true);

			var capaGrid1 = new qx.ui.layout.Grid(15,0);
			capaGrid1.setColumnAlign(0,"center","middle");
			capaGrid1.setColumnAlign(1,"left","middle");
			capaGrid1.setColumnWidth(1,250);

			var container1 = new qx.ui.container.Composite(capaGrid1);

			container1.add(imgWindow, {row:0,column:0});
			container1.add(txtMsg, {row:0,column:1});

			win.add(container1);

			return win;
		},
		question : function (msg, response, context)
		{
			var win = this._Window("Pregunta", "ow/icons/16/ayuda2.png", "ow/icons/64/ayuda2.png", "Pruebita de un fucking Mensaje", response, context);
			win.addListener("close", function ()
			{
				response.call(context, respuesta);
			}, context);


			/*******************************************
							BOTONES DEL CARTEL
			*******************************************/

			var respuesta = 0;
			var btnAceptar = new qx.ui.form.Button("Aceptar");
			var btnCancelar = new qx.ui.form.Button("Cancelar");

			btnAceptar.addListener("execute", function ()
			{
				respuesta = 1;
				win.close();
			});
			btnCancelar.addListener("execute", function ()
			{
				respuesta = 2;
				win.close();
			});

			var container2 = new qx.ui.container.Composite(new qx.ui.layout.Canvas);
			container2.add(btnAceptar, {left: "25%"});
			container2.add(btnCancelar, {right: "25%"});

			win.add(container2);
			win.open();
		},
		alert : function (msg, response, context)
		{
			var win = this._Window("Alerta", "ow/icons/16/alerta.png", "ow/icons/64/alerta.png", msg);
			if ((response != null) && (context != null))
			{
				win.addListener("close", function ()
				{
					response.call(context, respuesta);
				}, context);
			}
			/*******************************************
							BOTONES DEL CARTEL
			*******************************************/

			var respuesta = 0;
			var btnAceptar = new qx.ui.form.Button("Aceptar");

			btnAceptar.addListener("execute", function ()
			{
				respuesta = 1;
				win.close();
			});

			var container2 = new qx.ui.container.Composite(new qx.ui.layout.Canvas);
			container2.add(btnAceptar, {left: "40%"});

			win.add(container2);
			win.open();
		},
		info : function (msg, response, context)
		{
			var win = this._Window("Información", "ow/icons/16/informacion.png", "ow/icons/64/informacion.png", msg);
			if ((response != null) && (context != null))
			{
				win.addListener("close", function ()
				{
					response.call(context, respuesta);
				}, context);
			}

			/*******************************************
							BOTONES DEL CARTEL
			*******************************************/

			var respuesta = 0;
			var btnAceptar = new qx.ui.form.Button("Aceptar");

			btnAceptar.addListener("execute", function ()
			{
				respuesta = 1;
				win.close();
			});

			var container2 = new qx.ui.container.Composite(new qx.ui.layout.Canvas);
			container2.add(btnAceptar, {left: "40%"});

			win.add(container2);
			win.open();
		},
		error : function (msg)
		{
			var win = this._Window("Error", "ow/icons/16/negacion.png", "ow/icons/64/negacion.png", msg);
			if ((response != null) && (context != null))
			{
				win.addListener("close", function ()
				{
					response.call(context, respuesta);
				}, context);
			}

			/*******************************************
							BOTONES DEL CARTEL
			*******************************************/

			var respuesta = 0;

			var btnAceptar = new qx.ui.form.Button("Aceptar");
			btnAceptar.addListener("execute", function ()
			{
				respuesta = 1;
				win.close();
			});

			var container2 = new qx.ui.container.Composite(new qx.ui.layout.Canvas);
			container2.add(btnAceptar, {left: "40%"});

			win.add(container2);
			win.open();
		}
	},
	construct : function (msg, type, response, context)
	{
//		this.base(arguments);

		this.addListener("close", function ()
		{
			response.call(context, "", this._respuesta);
		}, this);
//		this.addListener("close", function ()
//		{
//			this.fireDataEvent('cerro', this._respuesta);
//		}, this);
//		this.addListener("cerro", )

		switch(type) {
			case "alert": {
				var typeTitle = "Alerta";
				var iconTitle = "pruebas/16/alerta.png";
				var iconWindow = "pruebas/64/alerta.png";
			break;
			}
			case "error": {
				var typeTitle = "Error";
				var iconTitle = "pruebas/16/negacion.png";
				var iconWindow = "pruebas/64/negacion.png";				
			break;
			}
			case "info": {
				var typeTitle = "Información";
				var iconTitle = "pruebas/16/informacion.png";
				var iconWindow = "pruebas/64/informacion.png";				
			break;
			}
			case "question": {
				var typeTitle = "Pregunta";
				var iconTitle = "pruebas/16/ayuda2.png";
				var iconWindow = "pruebas/64/ayuda2.png";				
			break;
			}
			case "login": {
				var typeTitle = "Acceso Restringido";
				var iconTitle = "pruebas/16/candadoCerrado.png";
				var iconWindow = "pruebas/64/candadoCerrado.png";				
			break;
			}
		}
		
//		this._msgWindow = new qx.ui.window.Window(typeTitle);
			this.setCaption(typeTitle);
			this.setLayout(new qx.ui.layout.VBox(0,0));
			this.setShowStatusbar(false);	
			this.setShowClose(false);
			this.setShowMaximize(false);
			this.setAllowMaximize(false);
			this.setShowMinimize(false);
			this.setMarginLeft(0);
			this.setMarginRight(0);
			this.setWidth(350);
			this.setHeight(140);
			this.setModal(false);
			this.setMovable(true);
			this.setResizable(false);
			this.moveTo("33%","35%");
			this.setIcon(iconTitle);

			var capaGrid1 = new qx.ui.layout.Grid(15,0);
			capaGrid1.setColumnAlign(0,"center","middle");
			capaGrid1.setColumnAlign(1,"left","middle");
			capaGrid1.setColumnWidth(1,250);
			
			var container1 = new qx.ui.container.Composite(capaGrid1);
			
			this._imgWindow = new qx.ui.basic.Image(iconWindow);
			
			this._txtMsg = new qx.ui.basic.Label("<b>"+msg+"</b>");
				this._txtMsg.setRich(true);
			
			container1.add(this._imgWindow, {row:0,column:0});
			container1.add(this._txtMsg, {row:0,column:1});

		switch(type) {
			case "question":
			case "alert": {
					this._btnAcept();
					this._btnCancel();
					var container2 = new qx.ui.container.Composite(new qx.ui.layout.Canvas);
					container2.add(this._btnAcept, {left: "25%", bottom: "0%"});
					container2.add(this._btnCancel, {right: "25%", bottom: "0%"});
			break;
			}
			case "info":
			case "error": {
					this._btnAcept();
					var container2 = new qx.ui.container.Composite(new qx.ui.layout.Canvas);
					container2.add(this._btnAcept, {left: "40%", bottom: "0%"});
			break;
			}
			case "login": {
					this._txtUser = new qx.ui.form.ow.TextField("Usurario:");
					this._txtPass = new qx.ui.form.ow.PassField("Clave:");
					this._btnAcept();
						var containerBtn = new qx.ui.container.Composite(new qx.ui.layout.Canvas);
						containerBtn.add(this._btnAcept,{right:"0%", bottom:"0%"});
					var container2 = new qx.ui.container.Composite(new qx.ui.layout.Grid(0,0));
					container2.add(this._txtUser, {row:0,column:0});
					container2.add(this._txtPass, {row:1,column:0});
					container2.add(containerBtn, {row:2,column:0});
			break;
			}
		}
			this.add(container1);
			this.add(container2);
		
	},
	
/*
*****************************************************************************
     MEMBERS
*****************************************************************************
*/
	members :
	{
		_respuesta : null,
//		open:  function () {
//			this.open();
//		},
//		close: function () {
//			this.close();
//		},
		_btnCancel: function() {
					this._btnCancel = new qx.ui.form.Button("Cancelar");
					this._btnCancel.addListener("execute", function(){
					this._respuesta = false;
					this.close();
					}, this);
		},
		_btnAcept: function() {
					this._btnAcept = new qx.ui.form.Button("Aceptar");
					this._btnAcept.addListener("execute", function(){
					this._respuesta = true;
					this.close();
					
					}, this);
		}
	}
});
